package com.zc.operator.controller;

import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.operator.domain.ChargeStationAdjustPrice;
import com.zc.operator.service.IChargeStationAdjustPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调整电价Controller
 *
 * @author glb
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/operator/adjustPrice")
public class ChargeStationAdjustPriceController extends BaseController
{
    @Autowired
    private IChargeStationAdjustPriceService chargeStationAdjustPriceService;

    /**
     * 查询调整电价列表
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeStationAdjustPrice chargeStationAdjustPrice)
    {
        startPage();
        List<ChargeStationAdjustPrice> list = chargeStationAdjustPriceService.selectChargeStationAdjustPriceList(chargeStationAdjustPrice);
        return getDataTable(list);
    }

    /**
     * 导出调整电价列表
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:export')")
    @Log(title = "调整电价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeStationAdjustPrice chargeStationAdjustPrice)
    {
        List<ChargeStationAdjustPrice> list = chargeStationAdjustPriceService.selectChargeStationAdjustPriceList(chargeStationAdjustPrice);
        ExcelUtil<ChargeStationAdjustPrice> util = new ExcelUtil<>(ChargeStationAdjustPrice.class);
        util.exportExcel(response, list, "调整电价数据");
    }

    /**
     * 获取调整电价详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(chargeStationAdjustPriceService.selectChargeStationAdjustPriceById(id));
    }

    /**
     * 获取调整电价详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:getInfoByStationCode')")
    @GetMapping(value = "/getInfoByStationCode")
    public AjaxResult getInfoByStationCode(ChargeStationAdjustPrice chargeStationAdjustPrice)
    {
        ChargeStationAdjustPrice chargeStationAdjustPrice1 = chargeStationAdjustPriceService.selectChargeStationAdjustPriceByStationCode(chargeStationAdjustPrice);
        if(Objects.isNull(chargeStationAdjustPrice1)){
            return AjaxResult.success("操作成功","[]");
        }else{
            return AjaxResult.success(chargeStationAdjustPrice1);
        }

    }

    /**
     * 新增调整电价
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:add')")
    @Log(title = "调整电价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeStationAdjustPrice chargeStationAdjustPrice)
    {
        return toAjax(chargeStationAdjustPriceService.insertChargeStationAdjustPrice(chargeStationAdjustPrice));
    }

    /**
     * 修改调整电价
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:edit')")
    @Log(title = "调整电价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeStationAdjustPrice chargeStationAdjustPrice)
    {
        return toAjax(chargeStationAdjustPriceService.updateChargeStationAdjustPrice(chargeStationAdjustPrice));
    }

    /**
     * 删除调整电价
     */
    @PreAuthorize("@ss.hasPermi('operator:adjustPrice:remove')")
    @Log(title = "调整电价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chargeStationAdjustPriceService.deleteChargeStationAdjustPriceByIds(ids));
    }
}
